
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE PBDsk_Upsert_GigyaUser 
			@pGigyaUID		 varchar(256)
           ,@pLoginProvider  varchar(256)
           ,@pLoginProviderUID varchar(256)
           ,@pNickName	 varchar(256)
           ,@pEmail		 varchar(512)
           ,@pFName		 varchar(200)
           ,@pLName		 varchar(200)
           ,@pGender	 varchar(1)
           ,@pDateOfBirth smalldatetime
           ,@pCity		 varchar(200)
           ,@pState		 varchar(200)
           ,@pCountry	 varchar(200)
           ,@pZIP		 varchar(12)
           ,@pPhotoUrl	 varchar(1024)
           ,@pThumbnailUrl varchar(1024)
           ,@pProfileUrl varchar(1024)
           ,@pIsActive bit
           
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

BEGIN TRANSACTION Upsert 
	UPDATE [PBDsk_GigyaUser]
    SET 
	   [LoginProvider] = @pLoginProvider
      ,[LoginProviderUID] = @pLoginProviderUID
      ,[NickName] = @pNickName
      ,[Email] = @pEmail
      ,[FName] = @pFName
      ,[LName] = @pLName
      ,[Gender] = @pGender
      ,[DateOfBirth] = @pDateOfBirth
      ,[City] = @pCity
      ,[State] = @pState
      ,[Country] = @pCountry
      ,[ZIP] = @pZIP
      ,[PhotoUrl] = @pPhotoUrl
      ,[ThumbnailUrl] = @pThumbnailUrl
      ,[ProfileUrl] = @pProfileUrl
      ,[LastUpdDt] = GetDate()
      ,[IsActive] = @pIsActive
    WHERE 
		[GigyaUID] = @pGigyaUID
    
    
    if @@rowcount = 0 

	INSERT INTO [PBDsk_GigyaUser]
           ([GigyaUID]
           ,[LoginProvider]
           ,[LoginProviderUID]
           ,[NickName]
           ,[Email]
           ,[FName]
           ,[LName]
           ,[Gender]
           ,[DateOfBirth]
           ,[City]
           ,[State]
           ,[Country]
           ,[ZIP]
           ,[PhotoUrl]
           ,[ThumbnailUrl]
           ,[ProfileUrl]
           ,[StartDate]
           ,[LastUpdDt]
           ,[IsActive])
     VALUES
           (@pGigyaUID
           ,@pLoginProvider
           ,@pLoginProviderUID
           ,@pNickName
           ,@pEmail
           ,@pFName
           ,@pLName
           ,@pGender
           ,@pDateOfBirth
           ,@pCity
           ,@pState
           ,@pCountry
           ,@pZIP
           ,@pPhotoUrl
           ,@pThumbnailUrl
           ,@pProfileUrl
           ,GetDate()
           ,GetDate()
           ,@pIsActive)
    
    
COMMIT TRANSACTION Upsert     
    
    
END
GO
